package com.jet.core.result;

import lombok.Data;
import lombok.ToString;

@Data
@ToString
public class ResultJson<T> {

    private int code;

    private String msg;

    private T data;

    public static <T> ResultJson<T> ok() {
        return ok(null);
    }

    public static <T> ResultJson<T> ok(T o) {
        return new ResultJson<>(ResultCode.SUCCESS, o);
    }

    public static <T> ResultJson<T> failure() {
        return failure(ResultCode.SYSTEM_ERROR);
    }

    public static <T> ResultJson<T> failure(ResultCode code) {
        return new ResultJson<>(code);
    }

    public static <T> ResultJson<T> failure(int code, String msg) {
        return new ResultJson<>(code, msg);
    }

    public static <T> ResultJson<T> failure(int code, String msg, T data) {
        return new ResultJson<>(code, msg, data);
    }

    private ResultJson() {
    }

    public ResultJson(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
    }

    public ResultJson(ResultCode resultCode, T data) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMsg();
        this.data = data;
    }

    public ResultJson(int code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public ResultJson(int code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }
}
